Using the Compiler from the Command Line

The compiler can be used from the command line without the IDE. This action assumes you have the \lcc\bin directory in your PATH environment variable.

c:\lcc\project> type hello.c

#include <stdio.h>

int main(void) {

     printf(« hello\n ») ;

     return 0 ;

}

c:\lcc\project> lcc hello.c                      (1)

c:\lcc\project> lcclnk hello.obj                 (2)

c:\lcc\project> hello.exe                        (3)

hello

c:\lcc\project>

You must first compile the source file. You call up the compiler (lcc.exe). Next, you should link the resulting object file with lcclnk, the linker (2). The program can then be executed by typing its name.

Below you will find the command line options for the compiler and the linker.

To build a Windows executable using some resources, the sequence of commands could be:

c:\lcc\project> lcc win.c

c:\lcc\project> lrc win.rc

c:\lcc\project> lcclnk –subsystem windows win.obj win.res

c:\lcc\project> win

The only difference is that you should compile your resources using the lrc resource compiler and add the resulting windows.res to your link command line. Please note that you should specify ‘subsystem Windows’ in the linker command line to avoid having a blank window appear whenever you start your program.

The compiler driver

 

The lc.exe compiler driver has the following format:

 

lc [ compiler options] files… [linker options]

 

This means that you give it all the compiler options first, then the files you want to compile, then and the options you want for the linker pass. Things in brackets are optional. You can just use lc file.c and the driver will call the compiler without any options, as well as the linker if all compilation steps happen without any error.

Note that you can pass to the driver an ambiguous file specification like

lc *.c –o prog.exe

 

The “-o” option is to name the executable output file, and it is a linker option, that’s why it is placed after the c files proper.

 

The driver will assume that rc files should be compiled with the resource compiler lrc, and asm files will be assembled with lcc.

If more than one source file is given, the driver will write to stderr the name of the file that is currently being compiled, and will echo the linker command line.

If there are errors during the compilation of any one file, the compilation goes on with the next file, but the process will stop before the link step. The result code will be the number of errors in either the compilation or in the linking step.

The Compiler

 

The technical documentation for the compiler (how it works) is described in the ‘lcc-win32.doc’ document. Only the recognized command line options are listed below.

lcc-win32 Command Line Options

 

Option

Meaning

-A

All warnings will be active.

-ansic

Disallow the language extensions of lcc-win32: operator overloading and references will not be accepted.

-D

Define the symbol following the ‘D’. Example:

-DNODEBUG

The symbol NODEBUG is #defined. Note that there is NO space between the D and the symbol.

 

 

-E

Generate an intermediate file with the output of the preprocessor. The output file name will be deduced from the input file name, i.e., for a compilation of foo.c you will obtain foo.i.

 

-E+

Like the -E option, but instead of generating a #line xxx directive, the preprocessor generates a # xxx directive. Some systems need this option, specifically some versions of gcc.

 

-EP

Like the -E option, but no #line directives will be generated.

-errout=

Append the warning/error messages to the indicated file. Example :

errout=Myexe.err

This will append to Myexe.err all warnings and error messages.

 

-eN

Set the maximum error count to N. Example:

-e25

The compiler will stop after 25 errors.

 

 

-fno-inline

Disables any inling of functions. No inline expansion will be performed, even if optimizations or on.

 

-Fo<file name>

This forces the name of the output file. Normally lcc deduces that name from the name of the input file, i.e., for foo.c, foo.obj, or foo.asm, or foo.i will be generated.

This option allows you to specify another name. Please, be careful using it, since no checks are run on the name. You can, in principle, make careless errors, such as: lcc foo.c –Fogg.c and the output binary object file will be called gg.c..., which is not recommended.

 

-g2

Generate the debugging information. Two types of debug information will be generated: COFF and CodeView (NB09).

 

 -g3

Arrange for function stack tracing. If a trap occurs, the function stack will be displayed.

 

-g4

Arrange for function stack and line number tracing.

 

-g5

Arrange for function stack, line number, and return call stack corruption tracing.

-I

Add a path to the path included, i.e., to the path the compiler follows to find the header files. Example:

-Ic:\project\headers

Note that there is NO space between the I and the following path.

 

 

-M

Print in standard output the names of all files that the preprocessor has opened when processing the given input file. If the Fo option is active, printing will be done in the file indicated by the Fo option. No object file is generated.

 

-M1

Print in standard output each include file recursively, indicating where it is called from, and when it is closed.

 

-nw

No warnings will be emitted. Errors will be still printed.

 

-O

Optimize the output. This activates the peephole optimizer and the inline keyword. Do not use this option with the -g option above.

 

-p6

Enable Pentium III instructions

 

-S

Generate an assembly file. The output file name will be deduced from the input file name, i.e., for a compilation of foo.c you will obtain foo.asm.

-U

Undefine the symbol following the ‘U’.

 

 

-unused

Warns about unused assignments and suppresses the dead code. Use with care

-s n

Set the switch density to n that must be a value between 0.0 and 1.0. Example: -s 0.1

 

-v

Show compiler version and compilation date

 

-x

Generate browse information in an .xrf file.

 

 

-z

Generate a file with the intermediate language of lcc. The name of the generated file will have a ‘.lil’ extension (lcc’s intermediate language).

 

-Zp[1,2,4,8,16]

Set the default alignment in structures to one, two, four, etc. If you set it to one, this actually means no alignment at all.

 

File.asm

All files with a .asm extension are assumed to be files written for lcc’s assembler. Beware: the syntax of lcc’s assembler is radically different from all standard assemblers. See the chapter about the assembler for more information.